import java.net.PortUnreachableException;
import java.util.Scanner;

/**
 * Created with IntelliJ IEDA.
 * Description:
 * User:86186
 * Date:2022-06-02
 * Time:10:36
 */
class UserNameException extends Exception {
    public UserNameException(String message) {
        super(message); }
}

class PasswordException extends Exception {
    public PasswordException(String message) {
        super(message); }
}

public class Login {
    private final String userName = "admin";
    private final String password = "123456";

    public static void loginInfo(String userName, String password)throws UserNameException,PasswordException {
        if (!userName.equals(userName)) {
            throw new UserNameException("用户名错误！");
        }if (!password.equals(password)) {
            throw new PasswordException("用户名错误！");
        }System.out.println("登陆成功");
    }

    public static void main(String[] args) throws PasswordException,UserNameException {
        loginInfo("admin", "123456");
    }
}

 /*class NameException extends Exception {
    public NameException(String message) {
        super(message);
    }
}

 class PasswordException extends Exception {
    public PasswordException(String message) {
        super(message);
    }
}
public class TestClass {

    *//*作业标题(1784)
    自定义异常实现登录
            作业内容

    实现一个简单的控制台版用户登陆程序, 程序启动提示用户输入用户名密码. 如果用户名密码出错, 使用自定义异常的方式来处理*//*
    public class Login {
        //实现一个简单的控制台版用户登陆程序, 程序启动提示用户输入用户名密码.
        // 如果用户名密码出错, 使用自定义异常的方式来处理
        private String name = "yjy";
        private String password = "123456";

        public static void main(String[] args) throws PortUnreachableException, NameException{
            Scanner scanner = new Scanner(System.in);
            System.out.println("请输入用户名: ");
            String name = scanner.next();
            System.out.println("请输入密码: ");
            String password = scanner.next();
            login(name, password);
        }

        public static void login(String name, String password) throws PasswordException, NameException {
            if (!Login.name.equals(name)) {
                throw new NameException("用户名错误");
            }
            if (!Login.password.equals(password)) {
                throw new PasswordException("密码错误");
            }
            System.out.println("登陆成功!");

        }
    }
}*/
   /* private static void testMethod(){

        System.out.println("testMethod");

    }

    public static void main(String[] args) {

        ((TestClass)null).testMethod();

    }
*/
